package com.mingsoft.led.comm;

import java.io.IOException;
import java.io.InputStream;

import com.mingsoft.led.util.Utils;

public class DefaultInputThread extends Thread {

	private InputStream is = null;
	boolean alive = false;

	public DefaultInputThread(InputStream is) {
		this.is = is;
	}

	public void run() {
		byte[] b = new byte[1024];
		int len = 0;
		alive = true;
		while (alive && is != null) {
			try {
				len = is.read(b);
				if (len > 0) {
					System.out.println(new String(b, 0, len));
				}
			} catch (Throwable e) {
				e.printStackTrace();
				alive = false;
				try {
					is.close();
				} catch (IOException e1) {
					e1.printStackTrace();
				}
				is = null;
				break;
			}
			Utils.sleep(100);
		}
	}

	public boolean alive() {
		return alive;
	}
}
